<?php
/**
 * /nmox/modules/Forms.class.php
 * Forms Class Module
 * 
 * @author David Christian Liedle <david.liedle@gmail.com>
 * @link   http://nmox.org/
 *
 */

class Forms {
    
    var $forms;
    var $bforms;
    
    function Forms(){
        // constructor
        if( $_POST ) $this->handle_post();
        if( $_GET ) $this->handle_get();
    }
    
    function add_form($name, $action, $method="post"){
        $this->forms[$name] = array('id'=>$name, 'action'=>$action, 'method'=>$method);
    }
    
    function handle_post(){
        // what to do with POST vars
    }
    
    function handle_get(){
        // what to do with GET vars
    }
    
    function build_form($name, $conts=""){
        $this->bforms[$name]['start'] = "<form id=\"".$this->forms[$name]['id']."\" action=\"".$this->forms[$name]['action']."\" ";
        $this->bforms[$name]['start'] .= "enctype=\"application/x-www-form-urlencoded\">\n";
        $this->bforms[$name]['conts'] = $conts;
        $this->bforms[$name]['close'] = "</form>\n";
    }
    
    function make_text($name, $length="40"){
        // add a text field
        return "<input id=\"$name\" name=\"$name\" type=\"text\" />\n";
    }
    
    function make_pass($name){
        // create a password field
        return "<input id=\"$name\" name=\"$name\" type=\"password\" />\n";
    }
    
    function make_textarea($name, $cols="40", $rows="3", $default_text=FALSE){
        return "<textarea id=\"$name\" name=\"$name\" type=\"textarea\" cols=\"$cols\" rows=\"$rows\">$default_text</textarea>\n";
    }
    
    function make_login_form($form_name="form_login", $handler=FALSE){
        if( !$handler ) $handler = $PHP_SELF;
        $conts = $this->make_text("username");
        $conts .= $this->make_pass("password");
    }
    
}

locateMe("/nmox/modules/Forms.class.php");
